package com.iflytek.ssm.aspect;

import com.iflytek.ssm.utils.ParamUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LogAspect {

    @Around("execution(* com.iflytek.ssm.service.impl.UserServiceImpl.*(..))")
    public Object log(ProceedingJoinPoint joinPoint) throws Throwable {
        // 获取输入参数
        String parameters = ParamUtils.getParam(joinPoint);

        System.out.println("当前进入方法名称:" + joinPoint.getSignature().getName() + "  请求参数：" + parameters + "");

        // 执行业务本身的方法体
        Object object = joinPoint.proceed();

        System.out.println("当前退出方法名称:" + joinPoint.getSignature().getName() + "  返回结果：" + object);

        return object;
    }

    @Before("execution(* com.iflytek.ssm.service.impl.UserServiceImpl.*(..))")
    public void before() throws Throwable {
        // 获取输入参数
        System.out.println("BeforeBeforeBeforeBefore");
    }

    @After("execution(* com.iflytek.ssm.service.impl.UserServiceImpl.*(..))")
    public void after() throws Throwable {
        // 获取输入参数
        System.out.println("afterafterafterafterafter");
    }
}
